poste seu sistema de lotéria, e também tente trocar de sistema.
7
1.3k
info
Grupo: Lorde
Registrado: 22/07/12
Posts: 2.2k
Reputação: +453
Char no Tibia: Kissy

19 de junho de 2015 às 19:09
20 de junho de 2015 às 09:06
Sistema de Loteria:
local config = {
lottery_hour = "3 Hours", -- Time to next lottery (real time you set on globalevents.xml, its only for broadcast message.)
rewards_id = {2494, 2472, 2514, 2493, 2470, 2195, 2173, 2160, 2520}, -- Rewards ID
crystal_counts = 100, -- used only if on rewards_id you have crystal coins (ID: 2160).
website = "yes" -- Do you have `lottery` table in your database?
}
function onThink(interval, lastExecution)
local players = getPlayersOnline()
local list = {}
for i, tid in ipairs(players) do
list[i] = tid
end
local winner = list[math.random(1, #list)]
local random_item = config.rewards_id[math.random(1, #config.rewards_id)]
local item_name = getItemNameById(random_item)
local world = tonumber(getPlayerWorldId(winner))
if(random_item == 2160) then
doPlayerAddItem(winner, random_item, config.crystal_counts)
doBroadcastMessage('[Baiak Rock Lottery] Winner: '.. getCreatureName(winner) ..', Reward: '.. config.crystal_counts ..' '.. item_name ..'s! Congratulations! (Next Lottery in '.. config.lottery_hour ..')')
else
doBroadcastMessage('[Baiak Rock Lottery] Winner: '.. getCreatureName(winner) ..', Reward: '.. item_name ..'! Congratulations! (Next Lottery in '.. config.lottery_hour ..')')
doPlayerAddItem(winner, random_item, 1)
end
if(config.website == "yes") then
db.executeQuery("INSERT INTO `lottery` (`name`, `item`, `world_id`) VALUES ('".. getCreatureName(winner) .."', '".. item_name .."', '".. world .."');")
end
return TRUE
end
@up
info
Grupo: Herói
Registrado: 01/05/08
Posts: 2.6k
Reputação: +536
Gênero: Masculino

23 de junho de 2015 às 08:49
Melhor resposta
Tente assim:
local config = {
lottery_hour = "3 Hours", -- Time to next lottery (real time you set on globalevents.xml, its only for broadcast message.)
rewards_id = {2494, 2472, 2514, 2493, 2470, 2195, 2173, 2160, 2520}, -- Rewards ID
crystal_counts = 100, -- used only if on rewards_id you have crystal coins (ID: 2160).
website = "yes" -- Do you have `lottery` table in your database?
}
function onThink(interval, lastExecution)
local players = getPlayersOnline()
if #players > 0 then
local list = {}
for i, tid in ipairs(players) do
list[i] = tid
end
local winner = list[math.random(1, #list)]
local random_item = config.rewards_id[math.random(1, #config.rewards_id)]
local item_name = getItemNameById(random_item)
local world = tonumber(getPlayerWorldId(winner))
if(random_item == 2160) then
doPlayerAddItem(winner, random_item, config.crystal_counts)
doBroadcastMessage('[Baiak Rock Lottery] Winner: '.. getCreatureName(winner) ..', Reward: '.. config.crystal_counts ..' '.. item_name ..'s! Congratulations! (Next Lottery in '.. config.lottery_hour ..')')
else
doBroadcastMessage('[Baiak Rock Lottery] Winner: '.. getCreatureName(winner) ..', Reward: '.. item_name ..'! Congratulations! (Next Lottery in '.. config.lottery_hour ..')')
doPlayerAddItem(winner, random_item, 1)
end
if(config.website == "yes") then
db.query("INSERT INTO `lottery` (`name`, `item`, `world_id`) VALUES ('".. getCreatureName(winner) .."', '".. item_name .."', '".. world .."');")
end
end
return true
end
Editado Junho 23 por Bruno Minervino
info
Grupo: Herói
Registrado: 20/05/10
Posts: 3.4k
Reputação: +1.5k
Gênero: Masculino

23 de junho de 2015 às 08:56
e qual o erro?? vc usa sqlite ou mysql??
ele tinha um bug, se n tivesse nenhum online da erro...
local config = {
lottery_hour = "3 Hours", -- Time to next lottery (real time you set on globalevents.xml, its only for broadcast message.)
rewards_id = {2494, 2472, 2514, 2493, 2470, 2195, 2173, 2160, 2520}, -- Rewards ID
crystal_counts = 100, -- used only if on rewards_id you have crystal coins (ID: 2160).
website = "yes" -- Do you have `lottery` table in your database?
}
function onThink(interval, lastExecution)
if #getPlayersOnline() > 0 then
local players = getPlayersOnline()
local winner, r_item = players[math.random(1, #players)], config.rewards_id[math.random(1, #config.rewards_id)]
local item_name = getItemNameById(r_item)
doPlayerAddItem(winner, r_item, isItemStackable(r_item) and 100 or 1)
doBroadcastMessage('[Baiak Rock Lottery] Winner: '.. getCreatureName(winner) ..', Reward: '..(isItemStackable(r_item) and 100 or 1)..' '.. item_name ..'(s)! Congratulations! (Next Lottery in '.. config.lottery_hour ..')')
if(config.website == "yes") then
db.query("INSERT INTO `lottery` (`name`, `item`, `world_id`) VALUES ('".. getCreatureName(winner) .."', '".. item_name .."', '".. world .."');")
end
end
return true
end
Editado Junho 23 por Vodkart
23 de junho de 2015 às 12:32
Tente assim:
local config = { lottery_hour = "3 Hours", -- Time to next lottery (real time you set on globalevents.xml, its only for broadcast message.) rewards_id = {2494, 2472, 2514, 2493, 2470, 2195, 2173, 2160, 2520}, -- Rewards ID crystal_counts = 100, -- used only if on rewards_id you have crystal coins (ID: 2160). website = "yes" -- Do you have `lottery` table in your database? } function onThink(interval, lastExecution) local players = getPlayersOnline() if #players > 0 then local list = {} for i, tid in ipairs(players) do list[i] = tid end local winner = list[math.random(1, #list)] local random_item = config.rewards_id[math.random(1, #config.rewards_id)] local item_name = getItemNameById(random_item) local world = tonumber(getPlayerWorldId(winner)) if(random_item == 2160) then doPlayerAddItem(winner, random_item, config.crystal_counts) doBroadcastMessage('[Baiak Rock Lottery] Winner: '.. getCreatureName(winner) ..', Reward: '.. config.crystal_counts ..' '.. item_name ..'s! Congratulations! (Next Lottery in '.. config.lottery_hour ..')') else doBroadcastMessage('[Baiak Rock Lottery] Winner: '.. getCreatureName(winner) ..', Reward: '.. item_name ..'! Congratulations! (Next Lottery in '.. config.lottery_hour ..')') doPlayerAddItem(winner, random_item, 1) end if(config.website == "yes") then db.query("INSERT INTO `lottery` (`name`, `item`, `world_id`) VALUES ('".. getCreatureName(winner) .."', '".. item_name .."', '".. world .."');") end end return true end
Sistema do @Bruno Minervino deu certinho.
Já o do @Vodkart deu erro.
Mais obrigado pela atenção os dois.
Rep+
Resolvido



info
Grupo: Campones
Registrado: 07/06/15
Posts: 69
Reputação: 0
- Olá estou com um pequeno problema no sistema de loteria.
Ele entrega o item para jogador, faz tudo certo.
Mais não esta adicionando na tabela da database, que seria lottery, e da um pequeno erro, onde não parece na página de Loteria do meu site os ganhadores!
Alguém sabe por que? Vi vários com o mesmo problema!